package com.zlp.oauth.hancer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;

import java.util.HashMap;
import java.util.Map;

/**
 * MyTokenEnhancer 增加器
 * @date: 2021/3/30 15:33
 */
@Slf4j(topic = "MyTokenEnhancer")
public class MyTokenEnhancer implements TokenEnhancer {


    @Override
    public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {

        log.info("enter enhance method ====>");
        DefaultOAuth2AccessToken defaultOAuth2AccessToken = new DefaultOAuth2AccessToken(accessToken);
        Map<String, Object> additionalInformation = new HashMap<>(4);
        additionalInformation.put("eEnhancer","Enhancer info");
        defaultOAuth2AccessToken.setAdditionalInformation(additionalInformation);
//        defaultOAuth2AccessToken.setExpiration();
        return defaultOAuth2AccessToken;
    }
}
